/**
 * 向指定的tab页面注入脚本
 */
const injectScript = ( tab ) => {
    if( !/^chrome:\/\//.test( tab.url )){
        chrome.tabs.executeScript( tab.id, { file: 'js/content-script.js' }, () => {
            console.log('脚本注入成功');
        });
    };
};

// 右键菜单
chrome.contextMenus.create({
	title: "iCopy",
	onclick: (info, tab) => {
		injectScript( tab );
	}
});

// 插件按钮被点击
chrome.browserAction.onClicked.addListener( tab => {
    injectScript( tab );
});